﻿// Tribe Framework by Chinajade.
//
// LICENSE:
// This work is licensed under the
//     Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
// also known as CC-BY-NC-SA.  To view a copy of this license, visit
//      http://creativecommons.org/licenses/by-nc-sa/3.0/
// or send a letter to
//      Creative Commons // 171 Second Street, Suite 300 // San Francisco, California, 94105, USA.

using System;
using System.Diagnostics;
using System.Windows.Media;

using Styx.Common;



namespace Chinajade.Tribe
{
    [RevisionControlId("$Id: TribeLog.cs 8 2012-12-26 10:01:13Z chinajade247@gmail.com $")]
    public class TribeLog
    {
        public TribeLog(string packageName = "TRIBE_UNNAMED")
        {
            packageName = packageName ?? "";

            TribeRevisionControl revision = new TribeRevisionControl();

            packageName = string.Format("{0}-v{1}", packageName, revision.GetRevision());

            _prefixContractViolation = string.Format("[{0}, CONTRACT VIOLATION] ", packageName);
            _prefixDeveloperInfo = string.Format("[{0}-DEBUG] ", packageName);
            _prefixDiagnostic = string.Format("[{0}] ", packageName);
            _prefixMaintenanceError = string.Format("[{0}, MAINTENANCE ERROR] ", packageName);
            _prefixWrite = string.Format("[{0}] ", packageName);
            _prefixWarning = string.Format("[{0}, WARNING] ", packageName);
        }

        private string _prefixContractViolation;
        private string _prefixDeveloperInfo;
        private string _prefixDiagnostic;
        private string _prefixMaintenanceError;
        private string _prefixWarning;
        private string _prefixWrite;


        /// <summary>
        /// <para>Used to report violations of interface contracts.</para>
        /// </summary>
        /// <param name="location"></param>
        /// <param name="msgFormat"></param>
        /// <param name="args"></param>
        public void ContractViolation(StackTrace location, string msgFormat, params object[] args)
        {
            msgFormat = string.Format((msgFormat ?? ""), args);
            msgFormat = string.Format("{0} {1}\nLocation:\n{2}", _prefixContractViolation, msgFormat, location.ToString());
            Logging.Write(Colors.DarkRed, msgFormat);
        }


        /// <summary>
        /// <para>For DEBUG USE ONLY--don't use in production code!</para>
        /// </summary>
        /// <param name="msgFormat"></param>
        /// <param name="args"></param>
        public void DeveloperInfo(string msgFormat, params object[] args)
        {
            msgFormat = msgFormat ?? "";
            Logging.Write(Colors.GreenYellow, _prefixDeveloperInfo + msgFormat, args);
        }
        
        
        /// <summary>
        /// <para>Used to notify of details that support 'normal progress' messages.</para>
        /// </summary>
        /// <param name="msgFormat"></param>
        /// <param name="args"></param>
        public void Diagnostic(string msgFormat, params object[] args)
        {
            msgFormat = msgFormat ?? "";
            Logging.WriteDiagnostic(Colors.DarkRed, _prefixDiagnostic + msgFormat, args);
        }


        /// <summary>
        /// <para>MaintenanceErrors occur as a result of incorrect code maintenance.
        /// There is usually no corrective
        /// action a user can perform in the field for these types of errors.</para>
        /// </summary>
        /// <param name="msgFormat"></param>
        /// <param name="args"></param>
        public void MaintenanceError(string msgFormat, params object[] args)
        {
            msgFormat = msgFormat ?? "";
            Logging.Write(Colors.DarkRed, _prefixMaintenanceError + msgFormat, args);
        }


        /// <summary>
        /// <para>Used to notify of problems where corrective (fallback) actions are possible.</para>
        /// </summary>
        /// <param name="msgFormat"></param>
        /// <param name="args"></param>
        public void Warning(string msgFormat, params object[] args)
        {
            msgFormat = msgFormat ?? "";
            Logging.Write(Colors.DarkRed, _prefixWarning + msgFormat, args);
        }


        /// <summary>
        /// <para>Used to notify of normal progress updates.</para>
        /// </summary>
        /// <param name="msgFormat"></param>
        /// <param name="args"></param>
        public void Write(string msgFormat, params object[] args)
        {
            msgFormat = msgFormat ?? "";
            Logging.Write(_prefixWrite + msgFormat, args);
        }
    }
}
